//
//  LMJPresentationController.swift
//  WB
//
//  Created by KenLiang on 16/4/7.
//  Copyright © 2016年 KenLiang. All rights reserved.
//

import UIKit

class LMJPresentationController: UIPresentationController {

    // MARK:-懒加载属性
    private lazy var coverView : UIView = UIView()
    
    // MARK:- 系统回调函数
    override func containerViewWillLayoutSubviews() {
        super.containerViewWillLayoutSubviews()
        
        //设置单出View尺寸
        presentedView()?.frame = CGRect(x: 100, y: 55, width: 180, height: 250)
        
        //添加蒙版
        setupCoverView()
    }
    
    
}

// MARK:- 设置蒙版相关UI
extension LMJPresentationController {
    private func setupCoverView() {
        
        //添加蒙版
        containerView?.insertSubview(coverView, atIndex: 0)
        
        //蒙版属性
        coverView.backgroundColor = UIColor(white: 0.8, alpha: 0.2)
        coverView.frame = containerView!.bounds
        
        //添加手势
        let tapGes = UITapGestureRecognizer(target: self, action: "coverViewClick")
        coverView.addGestureRecognizer(tapGes)
    }
}

// MARK:- 监听手势
extension LMJPresentationController {
    @objc private func coverViewClick() {
        presentedViewController.dismissViewControllerAnimated(true, completion: nil)
    }
}